var util = require('../../utils/util.js')
var app = getApp()
Page({
  data: {
    // text:"这是一个页面"
    color: "window",
    message: "查看学堂画像",
    title: "文思学堂",
    src: '../../resources/logo_200_200.png',
    x: '',
    y: ''
  },

  onLoad: function (options) {
    
    // 页面初始化 options为页面跳转所带来的参数
    // util.goTo('../home/home?p=1', 1)
    this.setData({ version: app.version })
  },

  setLoading: function (e) {
    wx.showLoading({
      title: '加载中',
    })

    setTimeout(function () {
      wx.hideLoading()
    }, 2000)

    wx.navigateTo({
      url: '../test/test',
    });
  },

  //获取用户输入的用户名
  userNameInput: function (e) {
    this.setData({
      x: e.detail.value
    })
  },
  passWdInput: function (e) {
    this.setData({
      y: e.detail.value
    })
  },

  // login request
  login: function (e) {
    //空白判断
    if (this.data.x === '') {
      util.showMsg('账号不可为空')
    } else {
      util.showMsg('登录中')
      // console.log("用户名：" + this.data.x + " 密码：" + this.data.y);
      // console.log('url:', 'https://x.wensixuetang.com/login')
      wx.request({
        url: 'https://x.wensixuetang.com/login', //仅为示例，并非真实的接口地址
        method: 'POST',
        // dataType: 'json',
        data: {
          // name: this.data.x === 'lkj' ? '15226526638' : this.data.x,
          // pass: this.data.x === 'lkj' ? '526638' : this.data.y
          name: '18600201290',
          pass: 'lovelkj'
        },
        header: {
          // 'content-type': 'application/json' // 默认值
          "Content-Type": "application/x-www-form-urlencoded"
        },
        success: function (res) {
          setTimeout(function () {
            wx.hideLoading()
          }, 10000)
          console.log('res', res.data)
          if (res.data.result === 0) {
            util.showLoading(res.data.msg)
            app.exp = res.data.exp //设置登录会话
            app.login = res.data.info
            app.power = res.data.p
            // util.goTo('../home/home?p=' + res.data.p, 1)
            wx.switchTab({
              url: '/pages/home/home',
            })
            console.log('fff')
          } else {
            // util.showLoading(res.data.msg)
            util.showModal('提示', res.data.msg)
          }
        },
        fail: function (err) {
        },//请求失败
        complete: function (res) {
        }//请求完成后执行的函数
      })
    }
  },


  formSubmit: function (e) {
    console.log('formid', e.detail.formId)
  }
}); 